using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace AutumnEngine
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;        

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);


            //We tell the engine to startup, and give it objects it needs to function.
            Engine.Initialize(this,graphics);

            //Here we create our scene object. The code for this scene is in the file 'Scenes/MainMap.cs'
            MainMap map = new MainMap();
            //When this map is created, it adds a node to itself.
            //By deriving a class from Scene, we have control over what happens when it is updated, and that's where we control the node position relative to mouse.

            //We now add it to the engine.
            Engine.Modules.SceneManager.AddScene("My New Map", map);
            
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            //This lets the engine update our scenes and input, etc.
            Engine.Update(gameTime);      
            //You can also access the engine out here, rather than in your scene.
            if (Engine.Modules.Contains("Engine.KeyboardInput"))
            {
                if (Engine.Modules.KeyboardInput.IsKeyTriggered(Keys.Escape))
                    this.Exit();
            }
            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            //This draws the scene, and modules.
            Engine.Draw();
            base.Draw(gameTime);
        }
        
    }
}
